<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="browsermode" content="application" />
    <meta name="x5-page-mode" content="app" />
    <title>认证中心</title>
    <meta charset="utf-8" />
    <link href="../css/main.css?rev=@@hash" rel="stylesheet" />
    <style>
        body{
            width: 3.75rem;
            background: #1EB97E;
        }
        .cells_title {
            margin-top: 0;
            background-color: white;
            padding: .12rem .2rem;
            font-size: .16rem;
            height: .22rem;
            color: rgb(68,74,89);
        }
        .cells_title a {
            display: block;
            float: left;
            font-size: .16rem;
            height: .22rem;
        }
        .cells_title img {
            margin: 0.02rem .12rem;
            height: .16rem;
            width: .16rem;
            float: left;
            display: block;
        }
        .indentf {
            margin: .16rem;
            width: 90%;
        }
        .indentf_img {
			width: 3.43rem;
		    height: 1rem;
		    background: #fff;
		    border-radius: .1rem;
	        margin-bottom: .1rem;
        }
        .indentf_img>img,.indentf_img>div{
        	display: inline-block;
        	float: left;
        }
        .identiName{
        	height: 1rem;
        	line-height: 1rem;
        	color: #272323;
        	font-size: .14rem;
        	font-weight: bold;
        }
        .rightArrow{
        	float: right!important;
        }
		.indentf_img .imgTips {
		    width: 1.05rem;
        }
        .rightArrow{
		    width: .24rem;
		    margin-top: 0.35rem;
		    margin-right: .1rem;
        }
        .submitBtn {
        	width: 90%;
        	height: .45rem;
        	line-height: .45rem;
		    font-size: .15rem;
		    color: #17A66F;
		    background: #FEE580;
		    border-radius: .25rem;
		    margin: 0 auto;
			left: 50%;
		    transform: translate(-50%,0);
        	box-shadow: 0rem 0.03rem 0.06rem #17A66F;
        }

        .layer_dialog .layer_dialog_ft::after, .layer_dialog .layer_dialog_hd:after {
            border-top: 0px solid white;
        }
        .layer_dialog .layer_dialog_hd {
            padding: .05rem 0;
        }
		.layer_dialog .layer_dialog_box {
		    border-radius: .1rem; 
		}
		.layer_dialog .layer_dialog_ft{
			background-color: rgb(255, 255, 255)!important;
		}
		.layer_btn, .layer_btn.layer_btn_primary {
		    font-size: .15rem;
		    color: #ffffff;
		    background: #1eb97e;
		    border-radius: .25rem;
		}
        .identiRight{
            float: right!important;
            height: .96rem;
			line-height: .96rem;	
        }
        .identiStatus{
            font-family: PingFang-SC-Medium;
            font-size: .12rem;
            color: #1eb97e;
        }
    </style>
</head>
<body>
    <!-- 蒙版 -->
    <div class="layer_load">
        <div class="layer_mask"></div>
        <div class="layer_load_icon icon-loading"></div>
    </div>
    <!--<div class="cells_title">
        <a>基本信息</a><img src="../images/tip.png" alt="">
    </div>-->

    <div class="indentf">
    	<a style="display: none;" href="javascript:;" >
        	<div class="indentf_img">
	        	<img src="../img/identi2.png" class="imgTips">
	        	<div class="identiName">通讯录</div>
	        	<div class="identiRight">
	        		<span class=""></span>
	        		<img src="../img/rightArrow.png" class="rightArrow">
        	    </div>
	        	</div>
    	</a>
    	<a class="identiItem" id="carrier" href="javascript:;">
        	<div class="indentf_img">
	        	<img src="../img/identi1.png" class="imgTips">
	        	<div class="identiName">手机运营商</div>
	        	<div class="identiRight">
	        		<span class="identiStatus"></span>
	        		<img src="../img/rightArrow.png" class="rightArrow">
        	    </div>
        	</div>
    	</a>
    	<a class="identiItem" id="bindCard" href="javascript:;">
        	<div class="indentf_img">
        	
	        	<img src="../img/identi2.png" class="imgTips">
	        	<div class="identiName">银行卡信息</div>
	        	<div class="identiRight">
	        		<span class="identiStatus"></span>
	        		<img src="../img/rightArrow.png" class="rightArrow">
        	    </div>
	        	</div>
    	</a>
    </div>
    <div class="submitBtn">提交</div>
    <!-- 脚本 -->
    <script src="../lib/zepto.min.js?rev=@@hash"></script>
    <script src="../js/main.js?rev=@@hash"></script>
    <script>
        (function(global,userUtil,layer){        
            $("body").height(document.documentElement.clientHeight);
            var mobile=localStorage.getItem("moblie");
            var sessionId=userUtil.sid();
            var orderNo;
            var realName;
            var idCard=localStorage.getItem("idCard");
            var fromMywallet;
            var contactsProgress = localStorage.getItem("contactsProgress");
            var progressArr;
            var indexNum;
        	var mainUrl = "https://api.51datakey.com/h5/importV3/index.html#/";////魔蝎认证      
            var backUrl = "http://h5.pushunjinfuchina.com/trust/identification.html";///认证完成返回的URL页面       &backUrl="+backUrl+"
            var carrierUrl = mainUrl+"carrier?apiKey=56ed8b60cd154d5a83e998f74b4aa8c6&showTitleBar=NO&themeColor=1EB97E&backUrl="+backUrl+"&userId="+localStorage.getItem("userID");
            //var carrierUrl = mainUrl+"carrier?apiKey=1f3ec1b5b01546fc9fa3bd4eed4385dd&showTitleBar=NO&themeColor=1EB97E&userId="+localStorage.getItem("userID");//测试
            if(global.query){
                fromMywallet=global.query;
                orderNo = global.query['orderNo'];
            }
            

            // 弹窗

            var layers = (function () {
                var _tips_timeout;
                return {          
			        alert: function (obj) {
			            var conf = {
			                title: "提 示",
			                content: "为了确保您的申请快速通过，需要您提供一位通讯录中常用联系人",
			                btnText: "确 定",
			                btnEvent: function () { }
			            };
			            if (typeof obj == "string") { obj = { content: obj } };
			            $.extend(conf, obj);
			            if ($(".alert").length == 0) {
			                $("body").append("<div class='layer_dialog alert'><div class='layer_mask'></div><div class='layer_dialog_box'><div class='layer_dialog_hd'><span class='layer_dialog_title'></span><i class='layer_btn_close icon-close' style='display:none'></i></div><div class='layer_dialog_cn'></div><div class='layer_dialog_ft'><a class='layer_btn layer_btn_primary'></a></div></div></div>");
			            }
			            $(".alert").addClass("on");
			            $(".alert .layer_dialog_title").text(conf.title);
			            $(".alert .layer_dialog_cn").html(conf.content);
			            $(".alert .layer_btn").text(conf.btnText).off("click").on("click", function () { conf.btnEvent(); close();jsBridgess.getContacts();  });
			            $(".alert .layer_btn_close").off("click").on("click", function () { conf.btnEvent(); close(); });
			
			            function close() {
			                $(".alert").removeClass("on");
			            }
			        }                    
                }
            })();

            //获取认证进展状态
            function getProgress(){
                $.ajax({
                    url: global.localUrl + "web/credit/getCompletion",
                    type: "post",
                    data: JSON.stringify({"sessionId": sessionId}),
                    contentType: 'application/json;charset=utf-8',
                    success: function (re) {
                        if (1 == re.code) {
                            var _data=re.data;
                            idCard=_data.idCardNo;
                            realName=_data.realName;
                            localStorage.setItem("contactsProgress",_data.contactsProgress);
                            progressArr = [_data.operatorProgress,_data.bankCardProgress];
                            for(var i=0;i<progressArr.length;i++){
                                if(progressArr[i] == 2){
                                    $('.identiStatus').eq(i).text("已认证");
                                }else if(progressArr[i] == 0 || progressArr[i] == null||progressArr[i] == 1){
                                    $('.identiStatus').eq(i).text("未认证");
                                }else if(progressArr[i] == 3){
                                    $('.identiStatus').eq(i).text("认证中");
                                }
                            }                              
                            indexNum=(_data.bankCardProgress==2?1:0)+(_data.operatorProgress==2?1:0)+1;

                            if(indexNum==3){
                                $(".submitBtn").click(function(){
                                    $(".submitBtn").off("click");
                                    //console.log(userUtil.userID)
                                     $.ajax({
                                        url: global.localUrl + "web/credit/submitCompletion",
                                        type: "post",
                                        data: JSON.stringify({"sessionId": sessionId,"orderNo":orderNo,"userUuid":userUtil.userID()}),
                                        contentType: 'application/json;charset=utf-8',
                                        success: function (re) {
                                            if (1 == re.code) {
                                                layer.tips("提交审核成功");
                                                setTimeout(function(){
//                                                  window.location.href=global.localUrl+'index.html';
                                                     window.location.href='../index.html';
                                                }, 2000);

                                            }else if(1046 == re.code){
                                                layer.tips("请设置交易密码");
                                                setTimeout(function(){
//                                                  window.location.href=global.localUrl+'trust/setPassword.html';
                                                    window.location.href='setPassword.html';
                                                }, 2000);
                                            }else{
                                                layer.tips(re.message);

                                            }
                                        },
                                        error: function () {
                                            layer.tips(global.netError);
                                        }
                                    });
                                })
                            }else{
                                $(".submitBtn").click(function(){
                                    $(".submitBtn").off("click");
                                });
                                $(".submitBtn").css({"backgroundColor":"#bdac65"});
                            }

                        }else{
                            layer.tips(re.message);
                        }
                    },
                    error: function () {
                        layer.tips(global.netError);
                    }
                });
            }
             $('.identiItem').on('click',function(){
             	var step = $(this).index();
              	for(var i=0;i<progressArr.length;i++){
                    if(progressArr[i] != 2){
		                switch(step){
			               	case 1: window.location.href=carrierUrl;break;
			               	case 2: window.location.href="bindCard.html?orderNo="+orderNo;break;
		                }		                       	
                    }
	            }                    	 	
                       	
           })            
            //app交互
            var jsBridgess = (function () {   

                function connectWebViewJavascriptBridge(callback) {
                    if (window.WebViewJavascriptBridge) {
                        callback(WebViewJavascriptBridge);
                    } else {
                        document.addEventListener('WebViewJavascriptBridgeReady', function () {
                            callback(WebViewJavascriptBridge);
                        }, false)
                    }
                }
                connectWebViewJavascriptBridge(function (WebViewJavascriptBridge) {
                    WebViewJavascriptBridge.init(function (message, responseCallback) {

                    });
                    WebViewJavascriptBridge.registerHandler("contactsList", function(data, responseCallback) {
                        phoneNumbers=(data); 
                        $.ajax({
                            url: global.localUrl + "wallet/orders/saveHbUserContact",
                            type: "post",
                            data: JSON.stringify({"contactStr": (phoneNumbers),"sessionId": sessionId,"orderNo":orderNo}),
                            contentType: 'application/json;charset=utf-8',
                            success: function (re) {
                             
                            },
                            error: function () {
                                layer.tips(re.message);
                            }
                        });
                    });
                    WebViewJavascriptBridge.registerHandler("contacts", function(data, responseCallback) {
                        var datas=JSON.parse(data);
                        
                    });

                    fn && fn();

                })
                return {
                    init: function (fn) {
                        connectWebViewJavascriptBridge(function (WebViewJavascriptBridge) {
                            WebViewJavascriptBridge.init(function (message, responseCallback) {

                            });

                            fn && fn();
                        })
                    },       
                    getContacts: function (callback) {
                        WebViewJavascriptBridge.callHandler('getContacts', {}, function (response) { callback(response); });
                    }
                }
            })();            
            
            getProgress();
            var getgetProgressTime = setInterval(function(){
            	    if(indexNum != 3){
            	    	getProgress(); 
            	    }else{
            	    	clearInterval(getgetProgressTime);
            	    }
            },1000);      
   			if(contactsProgress == 2){
				close();
			}else{
				layers.alert();
			} 
        })(global,userUtil,layer)
    </script>
</body>
</html>